const mongoose = require('./db');
const { getId } = require('../utils/getMethods')

const activityRuleSchema = new mongoose.Schema({
	id: {
		type: Number,
		default: () => getId
	},
	ruleDesc: {
		type: String,
		required: true
	}
})
const categoryListSchema = new mongoose.Schema({
	id: {
		type: Number,
		unique: true,
		required: true,
		default: () => getId
	},
	name: {
		type: String,
		required: true
	},
	imgUrl: {
		type: String,
		required: true
	},
	parentId: {
		type: Number,
		required: true,
	},
	status: {
		type: Number,
		required: true
	},
})
const imagesListSchema = new mongoose.Schema({
	id: {
		type: Number,
		default: () => getId
	},
	skuId: {
		type: Number
	},
	imgName: {
		type: String
	},
	imgUrl: {
		type: String
	}
})
const skuAttrValueListSchema = new mongoose.Schema({
	id: {
		type: Number,
		default: () => getId
	},
	skuId: {
		type: Number
	},
	attrId: {
		type: Number
	},
	attrName: {
		type: String
	},
	attrValue: {
		type: String
	}
})
const skuProductListSchema = new mongoose.Schema({
	id: {
		type: Number,
		unique: true,
		required: true,
		default: () => getId
	},
	keyword: {
		type: String,
		required: true
	},
	skuType: {
		type: Number,
		required: true,
		default: 1
	},
	isNewPerson: {
		type: Number,
		default: 0
	},
	categoryId: {
		type: Number,
		required: true,
		unique: true,
		default: () => getId
	},
	categoryName: {
		type: String,
	},
	imgUrl: {
		type: String,
		required: true
	},
	title: {
		type: String,
		required: true
	},
	price: {
		type: Number,
		required: true
	},
	perLimit: {
		type: Number,
		required: true
	},
	sale: {
		type: Number,
		required: true
	},
	ruleList: Array,
	marketPrice: Number,
	skuName: String
})

const activityRuleListModel = mongoose.model('activityRuleList', activityRuleSchema, 'activityRuleList')
const skuProductListModel = mongoose.model('skuProductList', skuProductListSchema, 'skuProductList')
const categoryListModel = mongoose.model('categoryList', categoryListSchema, 'categoryList')
const imagesListModel = mongoose.model('imagesList',imagesListSchema,'imagesList')
const skuAttrValueListModel = mongoose.model('skuAttrValueList',skuAttrValueListSchema, 'skuAttrValueList')

module.exports = {
	activityRuleListModel,
	categoryListModel,
	skuProductListModel,
	imagesListModel,
	skuAttrValueListModel
}